#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5+5;
int T, n, a[MAXN];
bool f[1000005];

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> T;
    while(T--){
        cin >> n;
        memset(f,0,sizeof(f));
        long long ans = 0;
        for (int i = 1; i<=n; i++){
            cin >> a[i];
            if(f[a[i]]) ans += a[i];
            f[a[i]] = 1;
        }
        cout << ans << '\n';
    }
    return 0;
}
